#include <iostream>
#include <algorithm>
using namespace std;

bool isPrime(int n)
{
    if(n == 2) return true;
    if(n <= 1 || n % 2 == 0) return false;
    for(int i = 3; i * i <= n; i += 2)
    {
        if(n % i == 0) return false;
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    while(n--)
    {
        int a, b;
        cin >> a >> b;
        if((a != 1 && !isPrime(a)) || (b != 1 && !isPrime(b)))
        {
            cout << "NO" << endl;
            continue;
        }
        if(isPrime(a * b)) 
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    return 0;
}